/*
 * LocationPresenter.java
 * business
 *
 * Created by SunDing on 2017/1/9.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.location;

import com.yidiandao.business.data.bean.Tag;
import com.yidiandao.business.data.model.CommonModel;
import com.yidiandao.business.data.model.ICommonModel;
import com.yidiandao.business.ui.widget.view.SuperLoadingLayout;
import com.yidiandao.business.utils.BaiDuSdkHelper;

import java.util.List;

/** 首次打开app 定位选择 */
public class LocationPresenter implements LocationContract.Presenter {

    private final ICommonModel mModel;
    private LocationContract.View mView;

    public LocationPresenter(LocationContract.View view) {
        mView = view;
        mView.setPresenter(this);
        mModel = new CommonModel();
    }

    @Override
    public void start() {
        mModel.getCityList(
                mView.getPagerTag(),
                new ICommonModel.onGetDataListener() {
                    @Override
                    public void onSuccess(List<Tag> tags, List<String> citys) {
                        mView.refreshContent(mView.checkResultObject(tags));
                        mView.setCityList(tags);
                        startLocation(citys);
                    }

                    @Override
                    public void onFailed() {
                        mView.refreshContent(SuperLoadingLayout.STATE_ERROR);
                    }

                    @Override
                    public void onFinal() {
                    }
                });
    }

    private void startLocation(List<String> citys) {
        BaiDuSdkHelper utils = mView.getBaiDuUtils();
        utils.setCanUseCitys(citys, mView.getLocationTextView());
        utils.getAddress(mView.getPagerTag());
    }
}
